package com.lovo.service.impl;

import com.lovo.dao.UserDAO;
import com.lovo.model.UserDO;
import com.lovo.service.UserService;
import org.apache.tomcat.jni.Time;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    private UserDAO userDAO;

    @Override
    public UserDO findByID(Integer userId) {
        return userDAO.findById(userId).orElse(null);
    }

    @Override
    public List findAll() {
        return userDAO.findAll();
    }

    @Override
    public void save(UserDO userDO) {
        userDAO.save(userDO);
    }

    @Override
    public void update(UserDO userDO) throws InterruptedException {

        userDAO.save(userDO);
        Thread.sleep(15000);
    }

    @Override
    public void delete(UserDO userDO) {
        userDAO.delete(userDO);
    }

    @Override
    public UserDO validate(String phone, String pwd) throws InterruptedException {
        UserDO userDO = userDAO.findByPhoneAndPwd(phone,pwd);
        Thread.sleep(15000);
        return userDO;
    }

    @Override
    public List findCondition(String phone) {
        return userDAO.findCondition(phone);
    }

    @Override
    public void deleteByPhone(String phone) {
        userDAO.deleteByPhone(phone);
    }
}
